//单例模式的核心：确保只用一个实例，并提供全局访问
//动态的创建命名空间

var MyApp = {};

MyApp.namespace = function (name) {
    var parts = name.split('.');
    var current = MyApp;
    for (var i in parts){
        if(!current[parts[i]]){
            current[parts[i]] = {};
        }
        current = current[parts[i]];
    }
};

MyApp.namespace('event');
MyApp.namespace('dom.style');

console.dir(MyApp);

//使用闭包封装私有变量

var user = (function () {
    var __name = 'sven',__age = 29;
    return {
        getUserInfo:function () {
            return __name +'-'+__age;
        }
    }
})();

console.log(user.getUserInfo());